package com.element.service;

import com.element.dao.UserDao;
import com.element.entity.User;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Service
@Transactional
public class UserServiceImpl implements UserService {

    @Autowired
    private UserDao userDao;

    //查询所有用户信息
    @Override
    @Transactional(propagation = Propagation.SUPPORTS)
    public List<User> findAll() {
        return userDao.findAll();
    }

    // 保存用户信息
    @Override
    public void save(User user) {
        userDao.save(user);
    }

    // 修改用户信息
    @Override
    public void update(User user) {
        userDao.update(user);
    }

    // 根据id删除用户信息
    @Override
    public void delete(String id) {
        userDao.delete(id);
    }

    // 分页查询
    @Override
    public List<User> findByPage(Integer currentPage, Integer pageSize) {
        currentPage = (currentPage - 1) * pageSize;
        return userDao.findByPage(currentPage, pageSize);
    }

    // 查询总页数
    @Override
    public Long findTotal() {
        return userDao.findTotal();
    }
}
